<?php

namespace App\Notifications\OrderNotifications;

use App\Models\Master;
use App\Models\Order;
use App\Notifications\Channels\SmsChannel;
use App\Notifications\OrderNotification;
use App\Services\IMasterService;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;

class OrderAppointedNotification extends Notification implements OrderNotification
{
    use Queueable;

    private $order;

    /**
     * Create a new notification instance.
     *
     * @return void
     */
    public function __construct(Order $order)
    {
        $this->order = $order;
    }

    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return [SmsChannel::class];
    }

    /**
     * 发送短信
     * @param Master $master
     * @return array($phoneNum,$message)
     */
    public function toSms(Order $order)
    {
        $message = <<<EOT
【%s】您的家具服务订单将由%s(%s)为您提供服务，预计上门服务时间(%s-%s)。服务确认码为%s(师傅完成服务后请您告诉师傅该确认码)，期间如有特殊情况请及时与师傅沟通。
EOT;
        $message = sprintf($message,
            config('app.name'),
            $order->master->call_name,
            $order->master->phone,
            $order->status->door_time->format('m月d日 H:00'),
            $order->status->door_time->addHours(2)->format('H:00'),
            $order->confirm_code);
        return [$order->detail->customer_phone,$message];
    }
}
